import java.util.Arrays;

/**
 * @author LKQ
 * @date 2022/3/2 16:50
 * @description
 */
public class StockSpanner {
    public static void main(String[] args) {
        StockSpanner sc = new StockSpanner();
        System.out.println(sc.next(31));
        System.out.println(sc.next(41));
        System.out.println(sc.next(48));
        System.out.println(sc.next(59));
        System.out.println(sc.next(79));
    }

    /**
     * 存储股票的数组
     */
    int[] stock;
    /**
     * 容量
     */
    int capacity;
    /**
     * 数组当前数据
     */
    int size;
    public StockSpanner() {
        this.capacity = 10;
        stock = new int[capacity];
        size = 0;
    }

    public int next(int price) {
        if (size >= capacity) {
            grow();
        }
        stock[size] = price;
        int start = size, j = -1;
        for (int i = start - 1; i >= 0; i--) {
            if (price < stock[i]) {
                j = i;
                break;
            }
        }
        int ans = 1;
        size++;
        return Math.max(start - j, ans);
    }
    public void grow() {
        capacity *= 2;
        int[] newStock = new int[capacity];
        System.arraycopy(stock, 0, newStock, 0, stock.length);
        stock = newStock;
    }
}
